package com.xinshujia.quartz;

import com.xinshujia.job.SampleJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * *************************************
 * *   @author: 野狼上校               **
 * *   @since: 2024-07-23 13:17       **
 * *   @version: 1.0                  **
 * *************************************
 * <p>
 */
@Configuration
public class QuartzConfig {

 @Bean
 public JobDetail sampleJobDetail() {
  return JobBuilder.newJob(SampleJob.class)
          .withIdentity("sampleJob", "group1")
          .storeDurably()
          .build();
 }

 @Bean
 public Trigger sampleJobTrigger() {
  return TriggerBuilder.newTrigger()
          .forJob(sampleJobDetail())
          .withIdentity("sampleTrigger", "group1")
          .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                  .withIntervalInSeconds(10)
                  .repeatForever())
          .build();
 }
}
